package com.corewillsoft.fireflies.gameobjects.obstacles.trajectories;

import com.corewillsoft.fireflies.gameobjects.obstacles.trajectories.Trajectory.TrajectoryType;

import java.util.List;

/**
 * Factory for creation of trajectories processors of different types
 */
public class TrajectoryFactory {
	/**
	 * Creates and returns instance of trajectory class by known type of trajectory and its parameters
	 * @param type - type of trajectory
	 * @param trajectoryParameters - list of parameters for particular trajectory (see comments inside this method for description of parameters for each trajectory type)
	 * @return created instance of trajectory class
	 */
	public static Trajectory createTrajectory(TrajectoryType type, List<Float> trajectoryParameters) {
		Trajectory trajectory = null;
		switch (type) {
			case POINT:
				/*
				point trajectory;
				there are no input parameters for point trajectory (object doesn't move)
				*/
				trajectory = new PointTrajectory(trajectoryParameters);
				break;
			case CIRCULAR:
				/*
				circular trajectory; required parameters are:
				0 - x coordinate of circle center
				1 - y coordinate of circle center
				2 - radius of circle
				 */
				trajectory = new CircularTrajectory(trajectoryParameters);
				break;
			case RECTANGULAR:
				/*
				rectangular trajectory; required parameters are:
				0 - x coordinate of top left corner of the rectangle
				1 - y coordinate of top left corner of the rectangle
				2 - x coordinate of bottom right corner of the rectangle
				3 - y coordinate of bottom right corner of the rectangle
				*/
				trajectory = new RectangularTrajectory(trajectoryParameters);
				break;
			case POLYLINE:
				/*
				polyline trajectory; required parameters are:
				0 - number of initial segment of polyline where object is moving on (first segment has number 0)
				1 - x coordinate of first point of polyline
				2 - y coordinate of first point of polyline
				...
				2*N-1 - x coordinate of N-th point of polyline
				2*N - y coordinate of N-th point of polyline
				*/
				trajectory = new PolylineTrajectory(trajectoryParameters);
				break;
			default:
				trajectory = null;
		}
		if (trajectory == null)
			trajectory = new PointTrajectory(trajectoryParameters);

		return trajectory;
	}
}
